package com.gopay.common.rcs.dao.rims.impl;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.constants.rims.RimsStatus;
import com.gopay.common.domain.rims.RimsTmsEvaluateLog;
import com.gopay.common.rcs.dao.rims.RimsTmsEvaluateLogDAO;

/**
 * 
 * TMS风控识别订单日志表
 * 
 * @RimsTmsEvaluateLogDAOImpl.java
 * @author MA HUAN
 * @2014-11-24 下午8:11:35  www.gopay.com.cn Inc.All rights reserved.
 */
@Repository(value = "rimsTmsEvaluateLogDAO")
@SuppressWarnings({ "unchecked", "rawtypes" })
public class RimsTmsEvaluateLogDAOImpl extends BaseDAOImpl<RimsTmsEvaluateLog, Serializable> implements RimsTmsEvaluateLogDAO {

  
    @Override
    public List<RimsTmsEvaluateLog> listByRimsStatusAndTime(RimsStatus status, Date timeBefore) {
        if(status != null) {
            String hql = " from RimsTmsEvaluateLog log where log.rimsStatus = :RimsStatus and log.rimsTranTime < :TimeBefore";
            Map params = new HashMap();
            params.put("RimsStatus", status.value());
            params.put("TimeBefore", timeBefore);
            return super.findByHql(hql, params);
        }
        return null;
    }

    @Override
    public boolean updateStatusByTranCodeAndOrder(String tranCode, String tranOrder, RimsStatus status) {
        if(status != null) {
            String hql = " update RimsTmsEvaluateLog log set log.rimsStatus = :RimsStatus where log.rimsTranCode = :TranCode and log.rimsTranOrder = :TranOrder";
            Map params = new HashMap();
            params.put("RimsStatus", status.value());
            params.put("TranCode", tranCode);
            params.put("TranOrder", tranOrder);
            return super.updateByHql(hql, params) > 0;
        }
        return false;
    }

}
